<?php
declare (strict_types = 1);

namespace app\api\model\v1;

use think\Model;

/**
 * @mixin \think\Model
 */
class Users extends AppModel
{
    //
    protected $hidden = [
        'password'
    ];

    //单位
    public function unit(){
        return $this->belongsTo(Unit::class,'unit_id');
    }

    //行业
    public function industry(){
        return $this->belongsTo(Industry::class,'industry_id');
    }


    public static function saveUserExcel($arrData, $create_id)
    {
        if (!empty($arrData)) {
            foreach ($arrData as $key => $v) {
                $is_ex = Unit::where(['unit_title'=>$v[0]])->find();
                if (!is_null($is_ex)) {
                    self::create([
                        'username' => $v[1] ?? '',
                        'nickname' => $v[1] ?? '',
                        'mobile' => $v[2] ?? '',
                        'password' => password_hash('111111', PASSWORD_DEFAULT),
                        'unit_id' => $is_ex['id'],
                        'industry_id'=>1,
                        'create_id'=>$create_id,
                    ]);
                }

            }
            $result = true;
        } else {
            $result = false;
        }
        return $result;
    }
}
